<template>
	<view class="wrapper">
		<view class="fixHeader" :style="{padding:`calc(10rpx + ${safeTop}px) 0 0`}">
			<view class="titleName">随心购</view>
			<div class="nav-bar">
				<div class="keyword flex-start bfff">
					<u-icon name="search" color="#999999" size="20"></u-icon>
					<input type="text" confirm-type="search" @confirm="goSearch" v-model="keyWords" placeholder="输入关键词" placeholder-class="c999 f32" class="ml15 searchInp" />
				</div>
				<view class="searchType">
					<view class="typeList">
						<view class="typeItem" :class="{cur:lbid==v.lbid}" v-for="v in categorys" :key="v.lbid" @click="setNav(v.lbid)">
							{{v.lbmc}}
						</view>
					</view>
					<view class="typeEnter" @click="show=true"></view>
				</view>
			</div>
		</view>
		<view class="shopList" :style="{padding:`calc(300rpx + ${safeTop}px) 32rpx 24rpx`}">
			<view class="shopTag">				
				<view class="tagName" :class="{cur:sortBy=='price desc'}" @click="setSortBy('price desc')">价格升序</view>
				<view class="tagName" :class="{cur:sortBy=='price asc'}" @click="setSortBy('price asc')">价格降序</view>
				<!-- <view class="tagName cur">全部分类</view>
				<view class="tagName">积分价格<view class="tagArr"></view>
				</view>
				<view class="tagName">综合排序<view class="tagArr"></view>
				</view>-->
			</view> 
			<view class="mallList">
				<navigator hover-class="none" :url="'/pages/shopDetail/shopDetail?spid='+item.spid" class="shopBox"
					v-for="(item,index) in list">
					<view class="shopPic">
						<image :src="item.img" ></image>
					</view>
					<view class="shopText">
						<view class="shopName">{{item.spmc}}</view>
						<view class="shopPrice">
							<text><text class="shopCode">{{item.price}}</text>积分</text>
							<text>库存：{{item.stock}}</text>
						</view>
					</view>
				</navigator>			
			</view>
			<u-empty text="暂无商品" v-if="list.length==0" margin-top="200"></u-empty>
		</view>
		<!-- 类型弹出层 -->
		<u-popup :safeAreaInsetTop="false" mode="top" round="13" :show="show" @close="close" @open="open">
			<view>
				<view class="fixHeader posr" :style="{padding:`calc(10rpx + ${safeTop}px) 0 0`}">
					<view class="titleName">随心购</view>
					<div class="nav-bar">
						<div class="keyword flex-start bfff">
							<u-icon name="search" color="#999999" size="20"></u-icon>
							<input type="text" confirm-type="search" @confirm="goSearch" v-model="keyWords" placeholder="输入关键词" placeholder-class="c999 f32"
								class="ml15 searchInp" />
						</div>
					</div>
				</view>
				<div class="bfff f26 nav-main">
					<div class="fbold f30 mt40 mb40">全部分类</div>
					<div class="flex-start fWrap">
						<div class="nav center mr20" :class="{ctheme:lbid==v.lbid}" v-for="v in categorys" :key="v.lbid"
							@click="setNav(v.lbid)">
							{{v.lbmc}}</div>
					</div>
				</div>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				navIndex: 0,
				// 顶部弹窗
				show: false,
				categorys: [],
				lbid: '',
				list:[],
				keyWords:'',
				sortBy:"price desc",
				pageNum:1,
				
			}
		},
		onLoad() {
			this.getcategorys()
			
		},
		onShareAppMessage: function () {
		    return {
		      title: '分享',
		      path: '/shouye/shouye?id=123'
		    }
		  },
		onReachBottom() {
			this.pageNum++
			this.getList()
		},
		methods: {
			
			//查询分类
			getcategorys() {
				this.$http('/api/goods/categorys').then((r) => {
					console.log(r)
					this.lbid = r.data[0].lbid
					this.categorys = r.data
					this.getList()
				})				
			},
			// 查询商品
			getList() {
				this.$http('/api/goods/list',{
					lbid:this.lbid,
					keyWords:this.keyWords,
					sortBy: this.sortBy,
					pageNum: this.pageNum,
					pageSize:10
				}).then((r) => {
					console.log(r)
					this.list = this.list.concat(r.data) 					
				})
			},
			// 条件切换
			setNav(i) {
				this.lbid = i
				this.pageNum = 1
				this.list = []
				this.getList()				
			},
			setSortBy(e){
				this.sortBy = e
				this.pageNum = 1
				this.list = []
				this.getList()
			},
			// 关键字
			goSearch(){
				this.pageNum = 1
				this.list = []
				this.close()
				this.getList()
			},
			open() {
				// console.log('open');
			},

			close() {
				this.show = false
				// console.log('close');
			}
		}
	}
</script>

<style lang="scss">
	.nav-main {
		padding: 50rpx 36rpx 120rpx;
		border-radius: 0 0 13rpx 13rpx;

		.nav {
			width: 190rpx;
			height: 63rpx;
			background: #F5F5F5;
			border-radius: 13rpx;
			margin-top: 15rpx;
		}

		.ctheme {
			border: 1rpx solid #FF5555;
			background-color: #FFEEF1;
		}
	}

	.fixHeader {
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		background-image: linear-gradient(to right, rgb(255, 88, 88), rgb(248, 87, 165));
		z-index: 5;

		.titleName {
			color: #ffffff;
			font-size: 44rpx;
			line-height: 1;
			padding: 0 24rpx 48rpx;
			text-shadow: -1px 0px 1px rgba(200, 16, 46, 1);
		}
	}

	.nav-bar {
		width: 100%;
		background: linear-gradient(to bottom, #FEDAEB, #FDFAFB);
		border-radius: 40rpx 40rpx 0rpx 0rpx;
		padding: 25rpx 25rpx 0;
		box-shadow: 0rpx -4rpx 6rpx 0 #FF5859;

		.keyword {
			padding-left: 20rpx;
			width: 675rpx;
			height: 70rpx;
			box-shadow: 0rpx 0rpx 16rpx 2rpx #FDCBE0;
			border-radius: 35rpx;
			margin: 0 auto;

			.searchInp {
				font-size: 32rpx;
			}
		}

		.searchType {
			margin-top: 24rpx;
			display: flex;
			align-items: center;

			.typeList {
				flex: 1;
				white-space: nowrap;
				overflow-y: scroll;

				.typeItem {
					margin: 0 40rpx;
					position: relative;
					height: 84rpx;
					display: inline-flex;
					justify-content: center;
					align-items: center;
					font-size: 32rpx;
					color: #333333;
				}

				.cur {
					color: #FC3850;

					&::after {
						content: '';
						position: absolute;
						left: calc(50% - 60rpx);
						bottom: 0;
						background-color: #FD7D7E;
						width: 120rpx;
						height: 8rpx;
						border-radius: 35rpx 35rpx 0 0;
					}
				}
			}
		}

		.typeEnter {
			display: flex;
			background: url(/static/mall/shop_menuIcon.png) center no-repeat;
			width: 30rpx;
			height: 28rpx;
			background-size: 100% auto;
			margin-right: 20rpx;
			margin-left: 20rpx;
		}
	}

	.shopList {
		padding: 343rpx 32rpx 24rpx;
	}

	.shopTag {
		margin-top: 40rpx;
		margin-bottom: 30rpx;
		display: flex;
		justify-content: space-around;

		.tagName {
			display: flex;
			align-items: center;
			justify-content: center;
			color: #999999;

			.tagArr {
				width: 18rpx;
				height: 36rpx;
				background: url(/static/mall/shop_mallArr.png) center no-repeat;
				background-size: 100% auto;
				margin-left: 20rpx;
			}
		}

		.cur {
			color: #FC3850;

			.tagArr {
				background: url(/static/mall/shop_mallArr.png) center no-repeat;

			}
		}
	}

	.mallList {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;

		.shopBox {
			width: 330rpx;
			background: #ffffff;
			border-radius: 6px;
			overflow: hidden;
			margin-bottom: 30rpx;

			.shopPic {
				height: 320rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.shopText {
				padding: 30rpx 20rpx 34rpx;

				.shopName {
					font-size: 30rpx;
					line-height: 44rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
					margin-bottom: 20rpx;
				}

				.shopPrice {
					display: flex;
					justify-content: space-between;
					font-size: 24rpx;
					color: rgba(155, 155, 155, 1);

					text:nth-child(1) {
						font-size: 20rpx;
						color: rgba(255, 85, 85, 1);
					}

					.shopCode {
						margin-right: 8rpx;
						font-size: 28rpx !important;
					}
				}
			}
		}
	}
</style>